import axios from '../../g-server';
import { LoginParams, LoginResult, User } from '../../g-types/user';

/**
 * 登录API
 */
class LoginService {
  /**
   * 登录
   * @param params 登录参数
   * @returns 登录结果
   */
  async login(params: LoginParams): Promise<LoginResult> {
    // 模拟登录接口
    // 实际项目中应该调用真实API
    // return axios.post<LoginResult>('/auth/login', params);
    
    // 模拟登录成功响应
    return Promise.resolve({
      token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpYXQiOjE2MjUxMjY5MDAsImV4cCI6MTYyNTIxMzMwMH0.XM9-eAWHFYwRuQTFNlgkcN7OH64BrfHmYQ9ZUFIlL8Q',
      user: {
        id: 1,
        username: 'admin',
        nickname: '管理员',
        avatar: 'https://joeschmoe.io/api/v1/random',
        role: 'admin',
        permissions: ['system:*'],
        status: 1,
        createTime: '2023-01-01 00:00:00',
      },
    });
  }

  /**
   * 注销
   */
  async logout(): Promise<void> {
    // 模拟注销接口
    // 实际项目中应该调用真实API
    // return axios.post('/auth/logout');
    
    return Promise.resolve();
  }

  /**
   * 获取当前用户信息
   */
  async getCurrentUser(): Promise<User> {
    // 模拟获取当前用户信息接口
    // 实际项目中应该调用真实API
    // return axios.get<User>('/auth/current-user');
    
    return Promise.resolve({
      id: 1,
      username: 'admin',
      nickname: '管理员',
      avatar: 'https://joeschmoe.io/api/v1/random',
      role: 'admin',
      permissions: ['system:*'],
      status: 1,
      createTime: '2023-01-01 00:00:00',
    });
  }
}

export const LoginApi = new LoginService(); 